#include "Rectangle.hpp"
#include "Shader.hpp"

namespace ygg
{

Rectangle::Rectangle(const phx::vec2f &position, const phx::vec2f &size, const phx::Colorf &color) :
	mPos(position),
	mSize(size),
	mColor(color)
{
	
}

const phx::Colorf& Rectangle::getColor()
{
	return mColor;
}

void Rectangle::setColor(const phx::Colorf &color)
{
	mColor = color;
}

void Rectangle::setPosition(float x, float y)
{
	mPos.x = x;
	mPos.y = y;
}

void Rectangle::setPosition(const phx::vec2f &pos)
{
	mPos = pos;
}

void Rectangle::setSize(float width, float height)
{
	mSize.x = width;
	mSize.y = height;
}

void Rectangle::setSize(const phx::vec2f &size)
{
	mSize = size;
}

void Rectangle::render()
{
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(0); // Disable writing to depth buffer

	phx::DefaultShader::rectangle.use();
	phx::DefaultShader::rectangle.setValue("color", mColor);
	phx::DefaultShader::rectangle.setValue("rectanglePosition", phx::vec2f((mPos.x / 1280.0f) * 2.0f, (mPos.y / 768.0f) * 2.0f));
	phx::DefaultShader::rectangle.setValue("rectangleSize", phx::vec2f(mSize.x / 1280.0f, mSize.y / 768.0f));
	//setPosition(mPos);
	//setSize(mSize);
	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	glDisable(GL_BLEND);
	glDepthMask(1); // Enable writing to depth buffer
}

}